package com.link4a.doms.dao;

import java.util.Collection;

/**
 * @param <E>
 * @author brown
 */
public class Page<E> extends AbstractPagination {

	private int rowCount;

	private Collection<E> rows;

	public Page(Collection<E> rows, int rowCount, Pagination pagination) {
		this(rows, rowCount, pagination.getPage(), pagination.getPageSize());
	}

	public Page(Collection<E> rows, int rowCount, int page, int pageSize) {
		super(page, pageSize);
		this.rowCount = rowCount;
		this.rows = rows;
	}

	public void setRowCount(int rowCount) {
		this.rowCount = rowCount;
	}

	public void setRows(Collection<E> rows) {
		this.rows = rows;
	}

	public int getRowCount() {
		return rowCount;
	}

	public Collection<E> getRows() {
		return rows;
	}

	public int getPageCount() {
		return (rowCount / getPageSize() + (rowCount % getPageSize() == 0 ? 0 : 1));
	}

	public boolean isFirstPage() {
		return (getPage() == 1);
	}

	public boolean isLastPage() {
		return (getLastRow() >= rowCount);
	}
}
